package client.network.interactive;

import message.Message;
import message.types.stalkerstring.GetRoomFromNameAnswer;
import client.network.ServiceRequestCenter;

public class JoinRoomByNameRequest implements InteractiveRequest {
  
  private String roomname_;
  
  public JoinRoomByNameRequest(String roomname) {
    assert (roomname != null);
    roomname_ = roomname;
  }
  
  public boolean getReply(ServiceRequestCenter servicer, Message message) {
    if (message instanceof GetRoomFromNameAnswer) {
      GetRoomFromNameAnswer answer = (GetRoomFromNameAnswer)message;
      if (answer.getName().equals(roomname_)) {
        servicer.requestRegisterToRoom(answer.getCredential());
        return true;
      }
    }
    return false;
  }

  public void startRequest(ServiceRequestCenter servicer) {
    servicer.requestRoomFromName(roomname_);
  }

}
